Wikipedysta:AramilFeraxa/ReportSolver.js: Różnice pomiędzy wersjami

Z Wikipedii, wolnej encyklopedii
Usunięta treść Dodana treść
+ dysk. dla ZB
dr
Linia 66: Linia 66:
}
}
$(this).after(' | ');
$(this).after(' | ');
$(this).after($('<a href="javascript:void(0)" class="ReportSolver-edit-commentZB" data-section="' + sectionNumber + '">dodaj komentarz (?)</a>'));
$(this).after($('<a href="javascript:void(0)" class="ReportSolver-edit-commentZB" data-section="' + sectionNumber + '">zgłoś uwagi (?)</a>'));
$(this).after(' | ');
$(this).after(' | ');
$(this).after($('<a href="javascript:void(0)" class="ReportSolver-edit-wrongZB" data-section="' + sectionNumber + '"> (K)</a>'));
$(this).after($('<a href="javascript:void(0)" class="ReportSolver-edit-wrongZB" data-section="' + sectionNumber + '"> (K)</a>'));
Linia 221: Linia 221:
} else if (action === 'commentZB') {
} else if (action === 'commentZB') {
template = '{{komentarz}} ';
template = '{{komentarz}} ';
editSummary = 'Rozpoczęcie dyskusji';
editSummary = 'Zgłoszono uwagi';
statusTemplate = '?';
statusTemplate = '?';
}
}

Wersja z 14:14, 20 maj 2024

// <nowiki>
$(function () {
    var RS = {};
    const RSConfig = window.RSConfig || {
        allowedPages: []
    };
    window.ReportSolver = RS;
    var wgPageName = mw.config.get('wgPageName');
    RS.summary = ' - za pomocą [[Wikipedysta:AramilFeraxa/ReportSolver|ReportSolver]]';
    var MSG = {
        dialogTitle: 'Zamknij zgłoszenie z komentarzem',
        dialogCancel: 'Anuluj',
        dialogConfirm: 'Zatwierdź',
        dialogMessage: 'Wprowadź komentarz:',
        dialogInfo: 'Szablon i podpis zostaną wstawione automatycznie.'
    };
    RS.setup = function () {
        // dla WP:PdA
        if (wgPageName === 'Wikipedia:Prośby_do_administratorów') {
            $('span.mw-editsection-bracket:first-child').each(function () {
                try {
                    if (this.parentElement.childNodes.length > 1 && this.parentElement.childNodes[1].href) {
                        sectionNumber = this.parentElement.childNodes[1].href.match(/action=edit&section=(\d+)/)[1];
                    }
                    this.after(' | ');
                    $(this).after($('<a href="javascript:void(0)" class="ReportSolver-edit-expired" data-section="' + sectionNumber + '"> (K)</a>'));
                    $(this).after($('<a href="javascript:void(0)" class="ReportSolver-mark-expired" data-section=' + sectionNumber + '>przedawnione</a>'));
                    $(this).after(' | ');
                    $(this).after($('<a href="javascript:void(0)" class="ReportSolver-edit-not-done" data-section="' + sectionNumber + '"> (K)</a>'));
                    $(this).after($('<a href="javascript:void(0)" class="ReportSolver-mark-not-done" data-section=' + sectionNumber + '>niezałatwione</a>'));
                    $(this).after(' | ');
                    $(this).after($('<a href="javascript:void(0)" class="ReportSolver-edit-rejected" data-section="' + sectionNumber + '"> (K)</a>'));
                    $(this).after($('<a href="javascript:void(0)" class="ReportSolver-mark-rejected" data-section=' + sectionNumber + '>odrzucone</a>'));
                    $(this).after(' | ');
                    $(this).after($('<a href="javascript:void(0)" class="ReportSolver-edit-done" data-section="' + sectionNumber + '"> (K)</a>'));
                    $(this).after($('<a href="javascript:void(0)" class="ReportSolver-mark-done" data-section=' + sectionNumber + '>Oznacz jako załatwione</a>'));
                } catch (e) {

                }
            });
            // dla WP:PUR
        } else if (wgPageName === 'Wikipedia:Wersje_przejrzane/Przyznawanie_uprawnień') {
            $('span.mw-editsection-bracket:first-child').each(function () {
                try {
                    var sectionNumber = null;
                    if (this.parentElement.childNodes.length > 1) {
                        sectionNumber = this.parentElement.childNodes[1].href.match(/action=edit&section=(\d+)/)[1];
                    }
                    this.after(' | ');
                    $(this).after($('<a href="javascript:void(0)" class="ReportSolver-edit-rejectedPUR" data-section="' + sectionNumber + '"> (K)</a>'));
                    $(this).after($('<a href="javascript:void(0)" class="ReportSolverPUR-mark-rejected" data-section=' + sectionNumber + '>odmowa</a>'));
                    this.after(' | ');
                    $(this).after($('<a href="javascript:void(0)" class="ReportSolver-edit-donePUR" data-section="' + sectionNumber + '"> (K)</a>'));
                    $(this).after($('<a href="javascript:void(0)" class="ReportSolverPUR-mark-granted" data-section=' + sectionNumber + '>włączone</a>'));
                } catch (e) {

                }
            });
            // dla Wikipedia:Zgłoś_błąd_w_artykule
        } else if (wgPageName === 'Wikipedia:Zgłoś_błąd_w_artykule') {
            $('span.mw-editsection-bracket:first-child').each(function () {
                try {
                    var sectionNumber = null;
                    if (this.parentElement.childNodes.length > 1) {
                        sectionNumber = this.parentElement.childNodes[1].href.match(/action=edit&section=(\d+)/)[1];
                    }
                    $(this).after(' | ');
                    $(this).after($('<a href="javascript:void(0)" class="ReportSolver-edit-commentZB" data-section="' + sectionNumber + '">zgłoś uwagi (?)</a>'));
                    $(this).after(' | ');
                    $(this).after($('<a href="javascript:void(0)" class="ReportSolver-edit-wrongZB" data-section="' + sectionNumber + '"> (K)</a>'));
                    $(this).after($('<a href="javascript:void(0)" class="ReportSolverZB-mark-wrong" data-section=' + sectionNumber + '>błędne (!)</a>'));
                    $(this).after(' | ');
                    $(this).after($('<a href="javascript:void(0)" class="ReportSolver-edit-rejectedZB" data-section="' + sectionNumber + '"> (K)</a>'));
                    $(this).after($('<a href="javascript:void(0)" class="ReportSolverZB-mark-rejected" data-section=' + sectionNumber + '>odrzucone (-)</a>'));
                    $(this).after(' | ');
                    $(this).after($('<a href="javascript:void(0)" class="ReportSolver-edit-doneZB" data-section="' + sectionNumber + '"> (K)</a>'));
                    $(this).after($('<a href="javascript:void(0)" class="ReportSolverZB-mark-done" data-section=' + sectionNumber + '>Oznacz jako załatwione (+)</a>'));
                } catch (e) {

                }
            });
            // opcja domyślna
        } else if (wgPageName.startsWith('Wikipedia:Kawiarenka/') || wgPageName === 'Wikiprojekt:Czy_wiesz/Podziękowania' || RSConfig.allowedPages.includes(wgPageName) || [1, 15, 5, 103, 11].includes(mw.config.get('wgNamespaceNumber'))) {
            var processedSections = {};
            $('span.mw-editsection-bracket:first-child').each(function () {
                try {
                    var sectionNumber = null;
                    var childNode = this.parentElement.childNodes[1];
                    if (childNode && childNode.href !== undefined && childNode.href !== null) {
                        var match = childNode.href.match(/action=edit&section=(\d+)/);
                        if (match && match[1]) {
                            sectionNumber = match[1];
                        }
                    }
                    if (sectionNumber && !processedSections[sectionNumber]) {
                        processedSections[sectionNumber] = true;
                        $(this).after(' | ');
                        $(this).after($('<a href="javascript:void(0)" class="ReportSolver-edit-expired" data-section="' + sectionNumber + '"> (K)</a>'));
                        $(this).after($('<a href="javascript:void(0)" class="ReportSolver-mark-expired" data-section="' + sectionNumber + '">przedawnione</a>'));
                        $(this).after(' | ');
                        $(this).after($('<a href="javascript:void(0)" class="ReportSolver-edit-not-done" data-section="' + sectionNumber + '"> (K)</a>'));
                        $(this).after($('<a href="javascript:void(0)" class="ReportSolver-mark-not-done" data-section="' + sectionNumber + '">niezałatwione</a>'));
                        $(this).after(' | ');
                        $(this).after($('<a href="javascript:void(0)" class="ReportSolver-edit-rejected" data-section="' + sectionNumber + '"> (K)</a>'));
                        $(this).after($('<a href="javascript:void(0)" class="ReportSolver-mark-rejected" data-section="' + sectionNumber + '">odrzucone</a>'));
                        $(this).after(' | ');
                        $(this).after($('<a href="javascript:void(0)" class="ReportSolver-edit-done" data-section="' + sectionNumber + '"> (K)</a>'));
                        $(this).after($('<a href="javascript:void(0)" class="ReportSolver-mark-done" data-section="' + sectionNumber + '">Oznacz jako załatwione</a>'));
                    }
                } catch (e) {
                    console.error('Błąd podczas dodawania przycisku: ', e);
                }
            });
        }

		$('a.ReportSolver-mark-done').click(function (e) {
		    var sectionNumber = $(this).data('section');
		    $(this).text("Przetwarzanie...");
		    RS.doEdit(sectionNumber, '{{załatwione}}', 'Oznaczenie jako załatwione', '+');
		});
		
		$('a.ReportSolver-mark-rejected').click(function (e) {
		    var sectionNumber = $(this).data('section');
		    $(this).text("Przetwarzanie...");
		    RS.doEdit(sectionNumber, '{{odrzucone}}', 'Oznaczenie jako odrzucone', '-');
		});
		
		$('a.ReportSolver-mark-not-done').click(function (e) {
		    var sectionNumber = $(this).data('section');
		    $(this).text("Przetwarzanie...");
		    RS.doEdit(sectionNumber, '{{odrzucone|niezałatwione}}', 'Oznaczenie jako niezałatwione', '!');
		});
		
		$('a.ReportSolver-mark-expired').click(function (e) {
		    var sectionNumber = $(this).data('section');
		    $(this).text("Przetwarzanie...");
		    RS.doEdit(sectionNumber, '{{przedawnione}}', 'Oznaczenie jako przedawnione', '-');
		});
		
		$('a.ReportSolverPUR-mark-granted').click(function (e) {
		    var sectionNumber = $(this).data('section');
		    $(this).text("Przetwarzanie...");
		    RS.doEdit(sectionNumber, '{{załatwione|Włączone}}', 'Uprawnienia włączone', '+');
		});
		
		$('a.ReportSolverPUR-mark-rejected').click(function (e) {
		    var sectionNumber = $(this).data('section');
		    $(this).text("Przetwarzanie...");
		    RS.doEdit(sectionNumber, '{{odrzucone|Odmowa}}', 'Odmowa', '-');
		});
		
		$('a.ReportSolverZB-mark-done').click(function (e) {
		    var sectionNumber = $(this).data('section');
		    $(this).text("Przetwarzanie...");
		    RS.doEdit(sectionNumber, '{{załatwione}}', 'Oznaczenie jako załatwione', '+');
		});
		
		$('a.ReportSolverZB-mark-rejected').click(function (e) {
		    var sectionNumber = $(this).data('section');
		    $(this).text("Przetwarzanie...");
		    RS.doEdit(sectionNumber, '{{odrzucone}}', 'Oznaczenie jako odrzucone', '-');
		});
		
		$('a.ReportSolverZB-mark-wrong').click(function (e) {
		    var sectionNumber = $(this).data('section');
		    $(this).text("Przetwarzanie...");
		    RS.doEdit(sectionNumber, '{{odrzucone|Błędne}}', 'Oznaczenie jako błędne', '!');
		});
		
		RS.handleEditButtonClick();

    };

	RS.handleEditButtonClick = function () {
	    $(document).off('click', '[class^="ReportSolver-edit-"]').on('click', '[class^="ReportSolver-edit-"]', function (e) {
	        var sectionNumber = $(this).data('section');
			var $headline = $('span.mw-editsection a[href$="&section=' + sectionNumber + '"]').closest('.mw-editsection').prevAll('.mw-headline').first();
    		var sectionTitle = $headline.attr('id').replace(/_/g, ' ');
	        var pageTitle = mw.config.get('wgPageName');
	        var editSummary, template;
	
	        var classList = $(this).attr('class').split(/\s+/);
	        for (var i = 0; i < classList.length; i++) {
	            if (classList[i].startsWith('ReportSolver-edit-')) {
	                var action = classList[i].substring('ReportSolver-edit-'.length);
	                if (action === 'done') {
	                    template = '{{załatwione}}. ';
	                    editSummary = 'Oznaczenie jako załatwione';
	                    statusTemplate = '+';
	                } else if (action === 'rejected') {
	                    template = '{{odrzucone}}. ';
	                    editSummary = 'Oznaczenie jako odrzucone';
	                    statusTemplate = '-';
	                } else if (action === 'expired') {
	                    template = '{{przedawnione}}. ';
	                    editSummary = 'Oznaczenie jako przedawnione';
	                } else if (action === 'not-done') {
	                    template = '{{odrzucone|Niezałatwione}}. ';
	                    editSummary = 'Oznaczenie jako niezałatwione';
	                    statusTemplate = '!';
	                } else if (action === 'donePUR') {
	                    template = '{{załatwione|Włączone}}. ';
	                    editSummary = 'Uprawnienia włączone';
	                    statusTemplate = '+';
	                } else if (action === 'rejectedPUR') {
	                    template = '{{odrzucone|Odmowa}}. ';
	                    editSummary = 'Odmowa';
	                    statusTemplate = '-';
	                } else if (action === 'wrongZB') {
	                    template = '{{odrzucone|Błędne}}. ';
	                    editSummary = 'Oznaczenie jako błędne';
	                    statusTemplate = '!';
	                } else if (action === 'doneZB') {
	                    template = '{{załatwione}}. ';
	                    editSummary = 'Oznaczenie jako załatwione';
	                    statusTemplate = '+';
	                } else if (action === 'rejectedZB') {
	                    template = '{{odrzucone}}. ';
	                    editSummary = 'Oznaczenie jako odrzucone';
	                    statusTemplate = '-';
	                } else if (action === 'commentZB') {
	                    template = '{{komentarz}} ';
	                    editSummary = 'Zgłoszono uwagi';
	                    statusTemplate = '?';
	                }
	                break;
	            }
	        }
	
	        function ReportSolverDialog(config) {
	            ReportSolverDialog.super.call(this, config);
	        }
	        OO.inheritClass(ReportSolverDialog, OO.ui.ProcessDialog);
	
	        ReportSolverDialog.static.name = "ReportSolverDialog";
	        ReportSolverDialog.static.title = MSG.dialogTitle;
	        ReportSolverDialog.static.actions = [
	            {
	                label: MSG.dialogCancel,
	                flags: "safe",
	            },
	            {
	                action: 'submit',
	                label: MSG.dialogConfirm,
	                flags: ["primary", "progressive"]
	            }
	        ];
	
	        ReportSolverDialog.prototype.initialize = function () {
	            ReportSolverDialog.super.prototype.initialize.call(this);
	
	            var rootPanel = new OO.ui.PanelLayout({
	                padded: true,
	                expanded: false,
	            });
	
	            var commentInput = new OO.ui.MultilineTextInputWidget({
	                rows: 5,
	                value: '',
	                placeholder: 'Wprowadź komentarz...'
	            });
	            
				var selectedOptionLabel = new OO.ui.LabelWidget({
			    label: "Wybrana opcja: ",
			    classes: ['centered-label']
				});
				
				var editSummaryElement = $("<span>", {
				    html: editSummary,
				    class: "bold-text"
				});
				
				var infoElement = $("<span>", {
				    html: MSG.dialogInfo,
				    class: "red-text"
				});
				
				rootPanel.$element.append(commentInput.$element, infoElement, selectedOptionLabel.$element, editSummaryElement);
				this.$body.append(rootPanel.$element);
				
				mw.util.addCSS(".centered-label { display: flex; align-items: center; justify-content: center; margin: 10px; }");
				mw.util.addCSS(".bold-text { display: flex; align-items: center; justify-content: center; font-weight: bold; margin: 10px }");
				mw.util.addCSS(".red-text { display: flex; color: red; align-items: center; justify-content: center; font-weight: bold; margin: 10px }"); 
	        };
	
			ReportSolverDialog.prototype.getActionProcess = function (action) {
	            var dialog = this;
	            if(action === 'submit') {
	                var comment = this.$body.find('textarea').val();
	                var wikitext = template + comment;
	                RS.doEdit(sectionNumber, wikitext, editSummary, statusTemplate);
	                dialog.close();
	            }
	            return ReportSolverDialog.super.prototype.getActionProcess.call(this, action);
	        };
	
	        var reportSolverDialog = new ReportSolverDialog({
	            size: "large",
	        });
	
	        var windowManager = new OO.ui.WindowManager();
	        $(document.body).append(windowManager.$element);
	        windowManager.addWindows([reportSolverDialog]);
	        windowManager.openWindow(reportSolverDialog);
	    });
	};

	RS.doEdit = function (sectionNumber, comment, editSummary, status) {
		var $headline = $('span.mw-editsection a[href$="&section=' + sectionNumber + '"]').closest('.mw-editsection').prevAll('.mw-headline').first();
    	var sectionTitle = $headline.attr('id').replace(/_/g, ' ');
	    var pageTitle = mw.config.get('wgPageName');
        new mw.Api().get({
            action: 'parse',
            page: pageTitle,
            prop: 'wikitext',
            section: sectionNumber
        }).done(function (result) {
            var wikitext = result.parse.wikitext['*'];
            wikitext = wikitext.replace(/\{\{\s*Status\s+zgłoszenia\s*\|\s*[^\|\}]*\s*\}\}/g, '{{Status zgłoszenia|' + status + '}}');
            comment = comment.trim();
			if (!comment.endsWith('.')) {
				comment += '.';
			}
			wikitext += '\n:' + comment + ' ~~~~';
            new mw.Api().postWithEditToken({
                action: 'edit',
                title: pageTitle,
                section: sectionNumber,
                text: wikitext,
                summary: '/* ' + sectionTitle + ' */ ' + editSummary + RS.summary,
                minor: true,
                nocreate: true
            }).done(function (result) {
                if (result && result.edit && result.edit.result && result.edit.result === 'Success') {
                    location.reload();
                }
            });
        });
    };

});

mw.loader.using('mediawiki.api', function () {
    $(document).ready(function () {
        window.ReportSolver.setup();
    });
});
// </nowiki>